all files / datePicker/ calendarYear.vue

33.33% Statements 6/18
66.67% Branches 4/6
25% Functions 1/4
14.29% Lines 2/14
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                      1×                                                                                      
//
//
//
//
//
//
//
//
//
//
 
import yearButton from './yearButton'
export default {
  props: {
    maxDate: {
      type: Date
    },
    minDate: {
      type: Date
    },
    selectedDate: {
      type: Date
    }
  },
  computed: {
    years () {
      const minYear = this.minDate.getFullYear()
      const maxYear = this.maxDate.getFullYear()
      const years = []
      for (let year = minYear; year <= maxYear; year++) {
        years.push(year)
      }
      return years
    }
  },
  methods: {
    handleClick (year) {
      this.$emit('change', year)
    },
    scrollToSelectedYear (yearButtonNode) {
      const container = this.$refs.container
 
      const containerHeight = container.clientHeight
      const yearButtonNodeHeight = yearButtonNode.clientHeight || 32
 
      const scrollYOffset = (yearButtonNode.offsetTop + yearButtonNodeHeight / 2) - containerHeight / 2
      container.scrollTop = scrollYOffset
    }
  },
  components: {
    'year-button': yearButton
  }
}